package com.leeoohoo.config;

import com.oohoo.spacestationspringbootstarter.config.SpringUtils;
import org.springframework.data.redis.core.ReactiveRedisTemplate;
import reactor.core.publisher.Mono;

import java.time.Duration;

public class RedisUtils {

    private static ReactiveRedisTemplate<String, String> stringReactiveRedisTemplate;

    static {
        stringReactiveRedisTemplate = SpringUtils.getBean(ReactiveRedisTemplate.class);
    }

    public static Boolean set(String key, String value, Duration duration) {
        Mono<Boolean> set = stringReactiveRedisTemplate.opsForValue().set(key, value, duration);
        return set.block();
    }

    public static Boolean set(String key, String value) {
        Mono<Boolean> set = stringReactiveRedisTemplate.opsForValue().set(key, value);
        return set.block();
    }

    public static Mono<String> get(String key) {
        return stringReactiveRedisTemplate.opsForValue().get(key);
    }

}
